#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

import os
from admin import *
import cgi

form = cgi.FieldStorage()  

print u"Content-type: text/plain"
print

if form.has_key(u"session"): 
   session = form[u"session"].value

if form.has_key(u"directory"): 
   directory = form[u"directory"].value
else:
   print u"<br/>Erreur manque directory...***"


print u"<br/><br/>Documents dans le dossier <b>%s</b>.<br/><br/>" % directory
# GET LIST FILE
document_path = u"%sdocument/%s" % ( Glob.SITE_PATH, directory )

files_list = os.listdir(document_path)

if len(files_list) > 0:
  print u"<table border='0' cellpadding='0' cellspacing='0' align='center'><tr><td class='adminLabel'>Fichier</td><td class='adminLabel'>Action</td></tr>"
  for f in files_list:
    file_name = os.path.basename(f)
    print u"<tr><td class='adminField'><a href='document/%s/%s' target='_blank'>%s</a></td><td><a id='%s' href='#' onclick='deleteDocument(this.id)'><img src='/img/delete_icon.gif' alt='Supprimer' title='Supprimer le fichier'/></a></td></tr>" % ( directory, file_name, file_name, file_name )
  print u"</table><br/><br/>"
else:
  print u"Aucun documents...<br/><br/>"

print u"<br/><span id='upload_process'>Loading...<br/><img src='/img/loader.gif' /></span><span id='upload_result'></span><form method='post' action='uploadDoc.py' enctype='multipart/form-data' target='hiddeniframe' onsubmit='startUpload()'><input type='file' name='filename'><input type='hidden' name='directory' value='%s'><input type='submit' value='Upload'></form><iframe name='hiddeniframe' src='' class='hiddenTag'></iframe>" % directory
